# -*- makefile -*-

# Adjust these to reflect where you've installed gnulib.
GNULIB = ../gnulib
GNULIB_TOOL = $(GNULIB)/gnulib-tool

GNULIB_MODULES = \
	assert \
	byteswap \
	c-snprintf \
	c-strcase \
	c-strcasestr \
	c-ctype \
	c-strtod \
	c-xvasprintf \
	clean-temp \
	close \
	configmake \
	count-one-bits \
	crc \
	crypto/md4 \
	crypto/rijndael \
	dirname \
	dtoastr \
	environ \
	fatal-signal \
	fcntl \
	fpieee \
	fprintf-posix \
	full-read \
	full-write \
        fseeko \
        ftello \
	fwriteerror \
	getline \
	getpass \
	gettext \
	gettimeofday \
        getopt-gnu \
	gitlog-to-changelog \
	include_next \
	isfinite \
	isinf \
	isnan \
	intprops \
	inttostr \
	localcharset \
        mbchar \
        mbiter \
	memcasecmp \
	memchr \
	memchr2 \
	mempcpy \
	memrchr \
	minmax \
	mkdtemp \
	mkstemp \
	pipe2 \
	printf-posix \
	printf-safe \
	progname \
	rawmemchr \
	read-file \
	regex \
	relocatable-prog \
	rename \
	round \
	select \
	snprintf \
	snprintf-posix \
	sprintf-posix \
	stdarg \
	stdbool \
	stdint \
	strcasestr \
	stpcpy \
	strerror \
	strftime \
	strsep \
	strtod \
	strtok_r \
	sys_stat \
	tempname \
	termios \
	trunc \
	unicase/u8-casecmp \
	unicase/u8-casefold \
	unicase/u8-tolower \
	unicase/u8-toupper \
	unictype/ctype-print \
	unictype/category-of \
	unigbrk/uc-is-grapheme-break \
	unilbrk/u8-possible-linebreaks \
	uninorm/nfkd \
	unistd \
	unistr/u8-check \
	unistr/u8-cpy \
	unistr/u8-mblen \
	unistr/u8-mbtouc \
	unistr/u8-mbtoucr \
	unistr/u8-strlen \
	unistr/u8-strmbtouc \
	unistr/u8-strncat \
	unistr/u8-uctomb \
	uniwidth/u8-strwidth \
	unitypes \
	unlocked-io \
	vasprintf-posix \
	version-etc \
	version-etc-fsf \
	vfprintf-posix \
	vprintf-posix \
	vsnprintf \
	vsnprintf-posix \
	vsprintf-posix \
	xalloc \
	xalloc-die \
	xmalloca \
	xmemdup0 \
	xsize \
	xstrndup \
	xvasprintf

APP_ICONS = \
src/ui/gui/icons/apps/32x32/pspp.png \
src/ui/gui/icons/apps/22x22/pspp.png \
src/ui/gui/icons/apps/24x24/pspp.png \
src/ui/gui/icons/apps/256x256/pspp.png \
src/ui/gui/icons/apps/16x16/pspp.png \
src/ui/gui/icons/apps/48x48/pspp.png \
src/ui/gui/icons/apps/scalable/pspp.svg

CATEGORY_ICONS = \
src/ui/gui/icons/categories/16x16/align-left.png \
src/ui/gui/icons/categories/16x16/align-center.png \
src/ui/gui/icons/categories/16x16/align-right.png \
src/ui/gui/icons/categories/16x16/measure-scale.png \
src/ui/gui/icons/categories/16x16/measure-ordinal.png \
src/ui/gui/icons/categories/16x16/measure-nominal.png \
src/ui/gui/icons/categories/16x16/measure-date-scale.png \
src/ui/gui/icons/categories/16x16/measure-date-nominal.png \
src/ui/gui/icons/categories/16x16/measure-date-ordinal.png \
src/ui/gui/icons/categories/16x16/measure-time-scale.png \
src/ui/gui/icons/categories/16x16/measure-time-nominal.png \
src/ui/gui/icons/categories/16x16/measure-time-ordinal.png \
src/ui/gui/icons/categories/16x16/measure-string-nominal.png \
src/ui/gui/icons/categories/16x16/measure-string-ordinal.png \
src/ui/gui/icons/categories/16x16/measure-currency-scale.png \
src/ui/gui/icons/categories/16x16/measure-currency-nominal.png \
src/ui/gui/icons/categories/16x16/measure-currency-ordinal.png \
src/ui/gui/icons/categories/16x16/role-input.png \
src/ui/gui/icons/categories/16x16/role-target.png \
src/ui/gui/icons/categories/16x16/role-both.png \
src/ui/gui/icons/categories/16x16/role-none.png \
src/ui/gui/icons/categories/16x16/role-partition.png \
src/ui/gui/icons/categories/16x16/role-split.png

MIMETYPE_ICONS = \
src/ui/gui/icons/mimetypes/32x32/application-x-spss-por.png \
src/ui/gui/icons/mimetypes/32x32/application-x-spss-sav.png \
src/ui/gui/icons/mimetypes/32x32/application-x-spss-sps.png \
src/ui/gui/icons/mimetypes/32x32/application-x-spss-zsav.png \
src/ui/gui/icons/mimetypes/22x22/application-x-spss-por.png \
src/ui/gui/icons/mimetypes/22x22/application-x-spss-sav.png \
src/ui/gui/icons/mimetypes/22x22/application-x-spss-sps.png \
src/ui/gui/icons/mimetypes/22x22/application-x-spss-zsav.png \
src/ui/gui/icons/mimetypes/24x24/application-x-spss-por.png \
src/ui/gui/icons/mimetypes/24x24/application-x-spss-sav.png \
src/ui/gui/icons/mimetypes/24x24/application-x-spss-sps.png \
src/ui/gui/icons/mimetypes/24x24/application-x-spss-zsav.png \
src/ui/gui/icons/mimetypes/256x256/application-x-spss-por.png \
src/ui/gui/icons/mimetypes/256x256/application-x-spss-sav.png \
src/ui/gui/icons/mimetypes/256x256/application-x-spss-sps.png \
src/ui/gui/icons/mimetypes/256x256/application-x-spss-zsav.png \
src/ui/gui/icons/mimetypes/16x16/application-x-spss-por.png \
src/ui/gui/icons/mimetypes/16x16/application-x-spss-sav.png \
src/ui/gui/icons/mimetypes/16x16/application-x-spss-sps.png \
src/ui/gui/icons/mimetypes/16x16/application-x-spss-zsav.png \
src/ui/gui/icons/mimetypes/48x48/application-x-spss-por.png \
src/ui/gui/icons/mimetypes/48x48/application-x-spss-sav.png \
src/ui/gui/icons/mimetypes/48x48/application-x-spss-sps.png \
src/ui/gui/icons/mimetypes/48x48/application-x-spss-zsav.png \

MISC_ICONS = src/ui/gui/icons/splash.png


ACTION_ICONS = \
src/ui/gui/icons/actions/32x32/data-split-file.png \
src/ui/gui/icons/actions/32x32/data-select-cases.png \
src/ui/gui/icons/actions/32x32/data-weight-cases.png \
src/ui/gui/icons/actions/32x32/transform-compute.png \
src/ui/gui/icons/actions/32x32/edit-find.png \
src/ui/gui/icons/actions/32x32/edit-go-to-case.png \
src/ui/gui/icons/actions/32x32/edit-go-to-variable.png \
src/ui/gui/icons/actions/32x32/edit-insert-case.png \
src/ui/gui/icons/actions/32x32/edit-insert-variable.png \
src/ui/gui/icons/actions/32x32/edit-cut.png \
src/ui/gui/icons/actions/32x32/edit-copy.png \
src/ui/gui/icons/actions/32x32/edit-paste.png \
src/ui/gui/icons/actions/32x32/edit-undo.png \
src/ui/gui/icons/actions/32x32/edit-redo.png \
src/ui/gui/icons/actions/32x32/edit-select-all.png \
src/ui/gui/icons/actions/32x32/file-open-data.png \
src/ui/gui/icons/actions/32x32/file-save-data.png \
src/ui/gui/icons/actions/32x32/file-export-data.png \
src/ui/gui/icons/actions/32x32/file-print.png \
src/ui/gui/icons/actions/32x32/view-value-labels.png \
src/ui/gui/icons/actions/32x32/utilities-variables.png \
src/ui/gui/icons/actions/32x32/run-all.png \
src/ui/gui/icons/actions/24x24/data-split-file.png \
src/ui/gui/icons/actions/24x24/data-select-cases.png \
src/ui/gui/icons/actions/24x24/data-weight-cases.png \
src/ui/gui/icons/actions/24x24/transform-compute.png \
src/ui/gui/icons/actions/24x24/edit-find.png \
src/ui/gui/icons/actions/24x24/edit-go-to-case.png \
src/ui/gui/icons/actions/24x24/edit-go-to-variable.png \
src/ui/gui/icons/actions/24x24/edit-insert-case.png \
src/ui/gui/icons/actions/24x24/edit-insert-variable.png \
src/ui/gui/icons/actions/24x24/edit-cut.png \
src/ui/gui/icons/actions/24x24/edit-copy.png \
src/ui/gui/icons/actions/24x24/edit-paste.png \
src/ui/gui/icons/actions/24x24/edit-undo.png \
src/ui/gui/icons/actions/24x24/edit-redo.png \
src/ui/gui/icons/actions/24x24/edit-select-all.png \
src/ui/gui/icons/actions/24x24/file-open-data.png \
src/ui/gui/icons/actions/24x24/file-save-data.png \
src/ui/gui/icons/actions/24x24/file-export-data.png \
src/ui/gui/icons/actions/24x24/file-print.png \
src/ui/gui/icons/actions/24x24/view-value-labels.png \
src/ui/gui/icons/actions/24x24/utilities-variables.png \
src/ui/gui/icons/actions/24x24/run-all.png \
src/ui/gui/icons/actions/16x16/file-new-data.png \
src/ui/gui/icons/actions/16x16/file-syntax-data.png \
src/ui/gui/icons/actions/16x16/file-system-data.png \
src/ui/gui/icons/actions/16x16/file-open-data.png \
src/ui/gui/icons/actions/16x16/file-import-data.png \
src/ui/gui/icons/actions/16x16/file-export-data.png \
src/ui/gui/icons/actions/16x16/file-save-data.png \
src/ui/gui/icons/actions/16x16/file-save-as.png \
src/ui/gui/icons/actions/16x16/file-print.png \
src/ui/gui/icons/actions/16x16/file-rename-data-set.png \
src/ui/gui/icons/actions/16x16/file-display-information.png \
src/ui/gui/icons/actions/16x16/display-information-working-file.png \
src/ui/gui/icons/actions/16x16/display-information-external-file.png \
src/ui/gui/icons/actions/16x16/file-recently-used.png \
src/ui/gui/icons/actions/16x16/file-quit.png \
src/ui/gui/icons/actions/16x16/file-display-information.png \
src/ui/gui/icons/actions/16x16/edit-insert-variable.png \
src/ui/gui/icons/actions/16x16/edit-insert-case.png \
src/ui/gui/icons/actions/16x16/edit-go-to-variable.png \
src/ui/gui/icons/actions/16x16/edit-go-to-case.png \
src/ui/gui/icons/actions/16x16/edit-cut.png \
src/ui/gui/icons/actions/16x16/edit-copy.png \
src/ui/gui/icons/actions/16x16/edit-paste.png \
src/ui/gui/icons/actions/16x16/edit-delete.png \
src/ui/gui/icons/actions/16x16/edit-undo.png \
src/ui/gui/icons/actions/16x16/edit-redo.png \
src/ui/gui/icons/actions/16x16/edit-select-all.png \
src/ui/gui/icons/actions/16x16/edit-clear.png \
src/ui/gui/icons/actions/16x16/edit-find.png \
src/ui/gui/icons/actions/16x16/view-font.png \
src/ui/gui/icons/actions/16x16/view-value-labels.png \
src/ui/gui/icons/actions/16x16/data-sort-cases.png \
src/ui/gui/icons/actions/16x16/data-transpose.png \
src/ui/gui/icons/actions/16x16/data-aggregate.png \
src/ui/gui/icons/actions/16x16/data-split-file.png \
src/ui/gui/icons/actions/16x16/data-select-cases.png \
src/ui/gui/icons/actions/16x16/data-weight-cases.png \
src/ui/gui/icons/actions/16x16/run-all.png \
src/ui/gui/icons/actions/16x16/run-selection.png \
src/ui/gui/icons/actions/16x16/run-current-line.png \
src/ui/gui/icons/actions/16x16/run-to-end.png \
src/ui/gui/icons/actions/16x16/transform-compute.png \
src/ui/gui/icons/actions/16x16/transform-count.png \
src/ui/gui/icons/actions/16x16/transform-rank-cases.png \
src/ui/gui/icons/actions/16x16/transform-automatic-recode.png \
src/ui/gui/icons/actions/16x16/transform-in-to-same-variables.png \
src/ui/gui/icons/actions/16x16/transform-in-to-different-variables.png \
src/ui/gui/icons/actions/16x16/transform-run-pending.png \
src/ui/gui/icons/actions/16x16/analyze-descriptive-statistics.png \
src/ui/gui/icons/actions/16x16/analyze-compare-means.png \
src/ui/gui/icons/actions/16x16/analyze-univariate-analysis.png \
src/ui/gui/icons/actions/16x16/analyze-bivariate-correlation.png \
src/ui/gui/icons/actions/16x16/analyze-kmeans-cluster.png \
src/ui/gui/icons/actions/16x16/analyze-factor-analysis.png \
src/ui/gui/icons/actions/16x16/analyze-realiability.png \
src/ui/gui/icons/actions/16x16/analyze-regression.png \
src/ui/gui/icons/actions/16x16/analyze-non-parametric-statistics.png \
src/ui/gui/icons/actions/16x16/analyze-roc-curve.png \
src/ui/gui/icons/actions/16x16/utilities-variables.png \
src/ui/gui/icons/actions/16x16/utilities-data-file-comments.png \
src/ui/gui/icons/actions/16x16/windows-minimize-all.png \
src/ui/gui/icons/actions/16x16/windows-split.png \
src/ui/gui/icons/actions/16x16/help-reference-manual.png \
src/ui/gui/icons/actions/16x16/help-about.png


ICONS=$(CATEGORY_ICONS) $(ACTION_ICONS) $(MIMETYPE_ICONS) $(APP_ICONS) $(MISC_ICONS)

all: prep_ph  icons
	$(MAKE) -f Smake Makefile.in configure

icons: $(ICONS) src/ui/gui/icons/icon-names.c

src/ui/gui/icons/icon-names.c: $(MAKEFILE_LIST)
	$(RM) -f $@
	printf '/* This is a generated file. Do not edit. */\n' >> $@
	printf '#include "icon-names.h"\n\n' >> $@
	build-aux/icon-list action actions $(ACTION_ICONS) >> $@
	build-aux/icon-list category categories $(CATEGORY_ICONS) >> $@

src/ui/gui/icons/manifest: $(MAKEFILE_LIST)
	$(RM) $@
	printf '# This is a generated file. Do not edit.\n' >> $@
	printf 'icons =' >> $@
	for i in  $(ICONS); do \
	  printf ' \\\n\t '$$i >> $@; \
	done
	echo >> $@
	echo >> $@
	printf 'icon_srcs = ' >> $@
	for i in  $(ICONS); do \
	  printf ' \\\n\t '$$i | sed -e 's/\.png$$/.svg/' -e 's%/icons/%/artwork/%' >> $@ ; \
	done
	echo ' ' >> $@
	echo >> $@

.PHONY: prep_ph
prep_ph: 
	test -e ChangeLog || touch ChangeLog
	test -d m4 || mkdir m4
	touch m4/Makefile.am
	$(GNULIB_TOOL) --add-import --no-changelog --m4-base=gl/m4 \
		--source-base=gl --lib=libgl --tests-base=tests \
		--doc-base=gl/doc --aux-dir=build-aux  \
		--libtool $(GNULIB_MODULES)
	if (glibtoolize --version) >/dev/null 2>&1; then	\
		LIBTOOLIZE=glibtoolize;				\
	elif (libtoolize --version) >/dev/null 2>&1; then	\
		LIBTOOLIZE=libtoolize;				\
	else							\
		echo >&2 "libtoolize not found";		\
		exit 1;						\
	fi;							\
	$$LIBTOOLIZE --force --automake --copy

aclocal.m4:
	aclocal -I m4 -I gl/m4

configure: configure.ac aclocal.m4
	autoconf

config.h.in: configure.ac
	autoheader

Makefile.in: Makefile.am config.h.in aclocal.m4 src/ui/gui/icons/manifest
	automake --add-missing --copy --no-force --include-deps


gettextize:
	test -d m4 || mkdir m4
	touch m4/Makefile.am
	gettextize --force --no-changelog

check: all
	rm -rf _check
	mkdir _check
	cd _check && ../configure $(CONFIGUREFLAGS)
	cd _check && make distcheck
	rm -rf _check

_build: all
	test -d _build || mkdir _build
	cd _build && ../configure $(CONFIGUREFLAGS)

_debug: all
	test -d _debug || mkdir _debug
	cd _debug && ../configure $(CONFIGUREFLAGS) --enable-debug



PO_FILES = po/ChangeLog \
po/Rules-quot po/boldquot.sed		\
po/cat-id-tbl.c po/en@boldquot.header po/en@quot.header			\
po/insert-header.sin po/quot.sed po/remove-potcdate.sin po/stamp-po	\
po/Makevars.template po/pspp.pot

clean:
	rm -f config.sub config.guess config.rpath
	rm -fr autom4te.cache
	rm -f aclocal.m4
	rm -f missing mkinstalldirs
	rm -f install-sh
	rm -f configure Makefile 
	rm -f depcomp
	rm -rf intl gl
	rm -f m4/*.m4
	rm -f $(PO_FILES) po/*.gmo 
	rm -f mdate-sh texinfo.tex
	rm -f doc/stamp-vti
	rm -f config.h.in~
	rm -f config.h.in
	find . -name Makefile.in -exec rm -f {} \; 
	rm -f compile
	rm -f ltmain.sh
	rm -f reloc-ldflags install-reloc

.PHONY: all gettextize clean


# The "convert" program from imagemagick can be used to create png from svg but doesn't properly deal
# with the alpha channels.  Therefore, it is not recommended for production pspp builds, but might
# be useful to get something working on a platform which doesn't have a working gimp.

#svg2png=convert -background transparent $1 $3

src/ui/gui/icons/%.png: src/ui/gui/artwork/%.svg build-aux/svg2png src/ui/gui/icons/COPYING_CCBYSA3
	mkdir -p $(dir $@)
	build-aux/svg2png "$<" "$(lastword $^)" "$@"


src/ui/gui/icons/%.svg: src/ui/gui/artwork/%.svg
	mkdir -p $(dir $@)
	cp $< $@
